package com.rongshu.view.userInfo.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.userInfo.entity.MessageInfo;
import com.rongshu.view.userInfo.entity.SystemMessage;
import com.rongshu.view.userInfo.iview.MessageClassifyView;

import rx.Subscriber;

public class MessageClassifyPresenter extends BasePresenter<MessageClassifyView> {

    public MessageClassifyPresenter(Context context) {
        super(context);
    }

    /**
     * 我的系统消息
     */
    public void getSystemMessage(int user_id, int page, int pagesize, String sign) {
        RetorfitService.getSystemMessage(user_id, page, pagesize, sign)
                .compose(getView().<SystemMessage>bindToLife())
                .subscribe(new Subscriber<SystemMessage>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(SystemMessage systemMessage) {
                        if (getView() != null) {
                            getView().onSystemMessage(systemMessage);
                        }
                    }
                });
    }

    /**
     * 删除系统消息
     */
    public void getDeleteMsg(int obj_id, int type, String sign) {
        RetorfitService.getDeleteMsg(obj_id, type, sign)
                .compose(getView().<INetBean>bindToLife())
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {

                    }
                });
    }

    /**
     * 获取我的消息页面的未读信息数
     */
    public void getMsgCount(int user_id, String sign) {
        RetorfitService.getMsgCount(user_id, sign)
                .compose(getView().<MessageInfo>bindToLife())
                .subscribe(new Subscriber<MessageInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(MessageInfo info) {
                        if (getView() != null) {
                            getView().onMsgCount(info);
                        }
                    }
                });
    }
}
